package com.example.xyxwebbackend001.controller;

import com.example.xyxwebbackend001.common.CommonResult;
import com.example.xyxwebbackend001.model.entity.City;
import com.example.xyxwebbackend001.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Value;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/city")
public class CityController {
    @Autowired
    private CityService cityService;

    @Value("${amap.api-key}")
    private String apiKey;

    @RequestMapping("/all")
    public CommonResult<List<City>> getAllCities(){
        List<City> cities = cityService.getAllCities();
        return CommonResult.message(cities);
    }
    @GetMapping("/location/key")
    public CommonResult<Map<String, String>> getApiKey() {
        return CommonResult.message(Collections.singletonMap("key", apiKey));
    }
}
